import axios from "axios";
import nprogress from "nprogress";
import "nprogress/nprogress.css";
import {createUserTempId} from './userAbout'
import { getToken } from "./userAbout";

const request = axios.create({
  baseURL: '/api',
  timeout: 10000
})
// 添加请求拦截器
request.interceptors.request.use(function (config) {
  nprogress.start()
  config.headers.userTempId = createUserTempId()
  const token = getToken('token')
  if(token){
    config.headers.token = token
  }
  return config;
});

// 添加响应拦截器
request.interceptors.response.use(function (response) {
  nprogress.done()
  return response.data;
}, function (error) {
  console.log(error);
  nprogress.done()
  return new Promise(() => {})
});


export default request